<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../00.依赖包/react.development.js"></script>
  <script src="../00.依赖包/react-dom.development.js"></script>
  <script src="../00.依赖包/babel.min.js"></script>
  <script src="../00.依赖包/prop-types.js"></script>
</head>

<body>
  <div id="app"></div>
  <script type="text/babel">
    class App extends React.Component{
      state ={
        opacity:1
      }
        render(){
          let {opacity} = this.state
          return (
            <div>
               <h1 style={{opacity}}>React</h1>
               <button onClick={this.handle}>点击取消</button>
            </div>
          )
        }
        //组件挂载完成后添加的业务逻辑等需求 
        componentDidMount(){
          let {opacity} = this.state
        this.clearTime =  setInterval(()=>{
            opacity -=0.1
            if(opacity<=0){
              opacity=1
            }
            this.setState({opacity})
          })
        }
        //组件即将卸载清除定时器
        componentwillUnmount(){
          clearInterval(this.clearTime)
        }
        handle=()=>{
          //组件卸载
          root.unmount()
        } 

        
    }

    

    const root = ReactDOM.createRoot(document.getElementById('app'));
    root.render(<App/>)

  </script>
</body>

</html>